package com.xiaobing.common.entity.system;

import com.baomidou.mybatisplus.annotation.TableName;
import com.xiaobing.common.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Set;

/**
 * 角色表 sys_role
 *
 * @author xulk
 */
@Data
@TableName("sys_role")
@Schema(name = "SysRole", description = "角色表")
@NoArgsConstructor
@AllArgsConstructor
public class SysRole extends BaseEntity {


    @Schema(name = "角色名称")
    @NotBlank(message = "角色名称不能为空")
    @Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符")
    private String roleName;

    @Schema(name = "角色权限", hidden = true)
    @NotBlank(message = "权限字符不能为空")
    @Size(min = 0, max = 100, message = "权限字符长度不能超过100个字符")
    private String roleKey;

    @Schema(name = "角色排序")
    private Integer roleSort;

    @Schema(name = "数据范围（1：所有数据权限；2：自定义数据权限；3：本部门数据权限；4：本部门及以下数据权限；5：仅本人数据权限）")
    private String dataScope;

    /**
     * 菜单树选择项是否关联显示（ 0：父子不互相关联显示 1：父子互相关联显示）
     */
    private boolean menuCheckStrictly;

    @Schema(name = "部门树选择项是否关联显示（0：父子不互相关联显示 1：父子互相关联显示 ）")
    private boolean deptCheckStrictly;

    @Schema(name = "角色状态（0正常 1停用）")
    private String status;

    /**
     * 用户是否存在此角色标识 默认不存在
     */
    private boolean flag = false;

    @Schema(name = "菜单组")
    private Long[] menuIds;

    @Schema(name = " 部门组（数据权限）")
    private Long[] deptIds;

    @Schema(name = "角色菜单权限")
    private Set<String> permissions;

    public boolean isAdmin() {
        return isAdmin(super.getId());
    }

    public static boolean isAdmin(Long roleId) {
        return roleId != null && 1L == roleId;
    }

}
